package main

import "fmt"

const (
	INT_MAX = 1<<31 - 1
	INT_MIN = -INT_MAX - 1
)

func reverse(x int) int {
	rev := 0
	for x != 0 {
		rev = rev*10 + x%10
		if rev > INT_MAX || rev < INT_MIN {
			return 0
		}
		x = x / 10
	}
	return rev
}

func main() {
	fmt.Println(reverse(123))
	//fmt.Println(reverse(-123))
}
